﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using DevExpress.XtraEditors.Controls;
using XCI.Config;
using XCI.Extensions;
using XCI.Windows;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    public partial class FrmIme : FrmBase
    {
        /// <summary>
        /// 
        /// </summary>
        public FrmIme()
        {
            InitializeComponent();
        }

        protected void Initialize()
        {
            ComboEnglish.Properties.Items.Clear();
            ComboEnglish.Properties.Items.BeginUpdate();

            ComboChinese.Properties.Items.Clear();
            ComboChinese.Properties.Items.BeginUpdate();

            ComboEnglish.Properties.Items.Add(new ImageComboBoxItem(null, -1));
            ComboChinese.Properties.Items.Add(new ImageComboBoxItem(null, -1));

            var imeNames = ImeHelper.GetImeLists();
            foreach (var inputLanguage in imeNames)
            {
                var img = ImeHelper.GetImeBitmap(inputLanguage) ?? XCI.Sys.Properties.Resources.Ime32;
                imageList1.Images.Add(img);
                int imageIndex = imageList1.Images.Count - 1;

                ComboEnglish.Properties.Items.Add(new ImageComboBoxItem(inputLanguage.LayoutName, imageIndex));
                ComboChinese.Properties.Items.Add(new ImageComboBoxItem(inputLanguage.LayoutName, imageIndex));
            }

            ComboEnglish.Properties.Items.EndUpdate();
            ComboChinese.Properties.Items.EndUpdate();

            //ComboEnglish.EditValue = ImeSetting.Instance.EnglishIme;
            //ComboChinese.EditValue = ImeSetting.Instance.ChineseIme;
        }

        /// <summary>
        /// 
        /// </summary>
        protected void Save()
        {
            //ImeSetting.Instance.EnglishIme = ComboEnglish.EditValue.ToStringOrEmpty();
            //ImeSetting.Instance.ChineseIme = ComboChinese.EditValue.ToStringOrEmpty();
            //SysRuntime.App.SaveUserSetting();
        }

        private void ImeForm_Load(object sender, EventArgs e)
        {
            Initialize();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Save();
            this.Close();
        }

        private void editEnglishTest_Enter(object sender, EventArgs e)
        {
            ImeHelper.SwtichIme(ComboEnglish.Text);
        }

        private void editChineseTest_Enter(object sender, EventArgs e)
        {
            ImeHelper.SwtichIme(ComboChinese.Text);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClean_Click(object sender, EventArgs e)
        {
            if (MessageBoxHelper.ShowWarnYesNo("确定要清除输入法设置吗?") == System.Windows.Forms.DialogResult.Yes)
            {
                //ImeSetting.Instance.EnglishIme = string.Empty;
                //ImeSetting.Instance.ChineseIme = string.Empty;
                //AppData.App.SaveUserSetting();
                this.Close();
            }
        }
    }
}